const Koa=require('koa');
const bodyParser=require('koa-bodyparser');
const app=new Koa();


app.use(bodyParser());

app.use(async ctx=>{
    if('GET'==ctx.method){
        ctx.body=`<form method=POST>
            username:<input type="text" name="username" value="Lily"><br>
            age:<input type="text" name="age" value="18"><br>
            email:<input type="text" name="email" value="aa@bb.com"><br>
            <input type="submit" value="Submit">
        </form>`;
    }else if('POST'==ctx.method){
        ctx.body=ctx.request.body;
    }else{
        ctx.body='404!!';
    }
});

app.listen(4000,()=>{
    console.log('Koa2 port:4000----'+new Date().toLocaleTimeString());
});